package com.twu.biblioteca;

import java.util.*;

/**
 * Created by kathy on 16/04/14.
 */
public class ListMoviesAction implements Action{

    private  Library library;

    public ListMoviesAction(Library library){
        this.library = library;
    }

    public void execute(){
        List<Movie> availableMovies = listAvailableMovies();
        printMovies(availableMovies);
    }

    private void printMovies(List<Movie> listOfMovies){

        System.out.print("Id \t\t" );
        System.out.print("Name \t\t" );
        System.out.print("Year \t\t");
        System.out.print("Director \t\t\t");
        System.out.print("Rating \n");

        for(Movie aMovie : listOfMovies){
            aMovie.printMovie();
        }
    }

    // This method is to get all movies which are ready to checkout
    public List<Movie> listAvailableMovies(){

        List<Movie> availableMovies = new ArrayList<Movie>();
        for(Movie aMovie : library.getMovieRepository()){
            if(aMovie.getIsAvailable())
                availableMovies.add(aMovie);
        }
        return availableMovies;
    }
}
